package com.enniswu.weitter.widget.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.enniswu.weitter.R;
import com.enniswu.weitter.entity.Message;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NotificationAdapter extends RecyclerView.Adapter {

    public static final int TYPE_NOTI = 0;
    public static final int TYPE_USER = 1;

    private List<Message> messages;

    public NotificationAdapter(List<Message> messages) {
        this.messages = messages;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == TYPE_NOTI) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_notification, parent, false);
            return new NotificationViewHolder(view);
        }
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_user, parent, false);
        return new UserAdapter.UserViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof NotificationViewHolder) {
            NotificationViewHolder nHolder = (NotificationViewHolder) holder;
            switch (position) {
                case 0:
                    nHolder.tvName.setText(nHolder.tvName.getContext()
                            .getString(R.string.notification_item_system));
                    nHolder.tvName.setTextColor(nHolder.tvName.getResources().getColor(R.color.text));
                    nHolder.ivIcon.setImageResource(R.drawable.ic_noti_system);
                    break;
                case 1:
                    nHolder.tvName.setText(nHolder.tvName.getContext()
                            .getString(R.string.notification_item_like));
                    nHolder.tvName.setTextColor(nHolder.tvName.getResources().getColor(R.color.text));
                    nHolder.ivIcon.setImageResource(R.drawable.ic_noti_like);
                    break;
                case 2:
                    nHolder.tvName.setText(nHolder.tvName.getContext()
                            .getString(R.string.notification_item_comment));
                    nHolder.tvName.setTextColor(nHolder.tvName.getResources().getColor(R.color.text));
                    nHolder.ivIcon.setImageResource(R.drawable.ic_noti_comment);
                    break;
            }
        }
        if (holder instanceof UserAdapter.UserViewHolder) {
            UserAdapter.UserViewHolder uHolder = (UserAdapter.UserViewHolder) holder;
        }
    }

    @Override
    public int getItemCount() {
        return messages.size() + 3;
    }

    @Override
    public int getItemViewType(int position) {
        if (position < 3)
            return TYPE_NOTI;
        return TYPE_USER;
    }

    static class NotificationViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_icon)
        ImageView ivIcon;
        @BindView(R.id.tv_name)
        TextView tvName;

        public NotificationViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
